<?php


class Ext_Utility_Misc
{
    public function __construct()
    {
        
    }
    
    public static function referfer()
    {
        $front = Zend_Controller_Front::getInstance();
        $bootstrap = $front->getParam('bootstrap');
        $view = $bootstrap->getResource('view');
        $defaultReferer = $view->baseUrl("");
        
        $referer = $defaultReferer;
        $httpHost = $_SERVER['HTTP_HOST'];
        if(isset($_SERVER['HTTP_REFERER'])){
            $httpReferer = $_SERVER['HTTP_REFERER'];
            $_httpReferer = preg_replace("/[a-zA-Z]+:\/\//si", "", $httpReferer);
            $fromServer = substr($_httpReferer, 0, strlen($httpHost));
            if($fromServer == $httpHost){
                if ($front->getRequest()->isPost()) {
                    $referer = "javascript:history.go(-1);";
                }elseif(preg_match("/$httpHost\/account\//si", $httpReferer)){
                    $referer = $defaultReferer;
                }else{
                    $referer = $httpReferer;
                }
            }
        }
        
        return $referer;
    }
}
